<template>
  <div>
    <header class="album-detail-header" v-if="!isShowRemove">
      <h3 class="album-title">{{albumName}}</h3>
      <ul class="album-detail-header-right">
        <li class="album-detail-remove" @click="clickRemoveImg"></li>
        <li class="album-detail-share" @click="clickShare"></li>
      </ul>
    </header>

    <header class="select-photo-header" v-else>
      <div class="select-header-left" @click="cancel">取消</div>
      <p class="select-header-center">{{removeImgTotal}}张照片、{{removeVideoTotal}}个视频</p>
      <div class="select-header-right" @click="clickRemoveText">删除</div>
    </header>

      <div class="photo-list-main" :style="isShowRemove?'padding-top:3.7rem':'padding-top:0rem'">
        <div class="photo-list-box">
          <p class="photo-list-time">{{createTime | createYear}}创建</p>
          <ul class="photo-list-img-box">
            <li class="photo-list-img" v-for="(v,k) in albumPhotolist" :key="k" @click="goPhotoDetail(v.id)">
              <div class="div-img" v-if="v.smImageUrl" :style="'backgroundImage: url('+(v.smImageUrl.substr(0,4).toLowerCase() == 'http' ? v.smImageUrl : resUrl+v.smImageUrl)+')'"></div>
              <!--<img v-if="v.smImageUrl" :src="v.smImageUrl.substr(0,4).toLowerCase() == 'http' ? v.smImageUrl : resUrl+v.smImageUrl" alt="">-->
              <span class="phpto-num" v-if="v.duration == 0">{{v.imgNum + v.videoNum}}张</span>
              <p class="phpto-video" v-if="v.duration != 0">{{v.duration | timeStamp}}</p>
              <label class="photo-check-label" :for="v.id" v-show="isShowRemove">
                <div>
                  <input type="checkbox" name="checkbox" class="weui-check" :id="v.id" :value="v" v-model="removeIdList">
                  <i class="weui-icon-checked"></i>
                </div>
              </label>

            </li>
          </ul>
          <p class="album-detail-num">{{imgTotal}}张照片，{{videoTotal}}个视频</p>
        </div>
      </div>

    <router-link :to="{name:'selectPhoto',query:{albumId:albumId,source:1}}" class="album-add"></router-link>

    <collection-footer></collection-footer>

  </div>
</template>

<script>
  import Moment from 'moment';
  import {ipconfig} from '../../../../../assets/js/ipconfig';
  import {timeMsec} from "../../../../../assets/js/tools";
  import {getCollectionList,deleteCollection,getMalbDirectoryInfo} from '../../../../../assets/js/getData';
  export default {
    name: "albumDetail",
    data(){
      return {
        resUrl:ipconfig.resUrl,//图片、视频、音频等资源访问路径
        albumId:null,//相册ID
        createTime:null,//相册创建时间
        albumName:'',//相册名称
        albumPhotolist:[],//相册照片列表
        isShowRemove:false,//是否显示删除
        imgTotal:0,//图片总数
        videoTotal:0,//视频总数
        removeIdList:[],//要删除的藏品ID列表
      }
    },
    created(){
      this.albumId = this.$route.query.albumId;

      //获取藏品列表
      this.getAlbumPhotolist();
      //获取文件夹详情
      getMalbDirectoryInfo(this.albumId).then(res => {
        if(res.data.reqResult.code > 0){
          console.log(res,'dddd');
          this.createTime = res.data.data.createTime;
          this.albumName = res.data.data.name;
        }else {
          Toast(res.data.reqResult.msg);
        }
      })
    },
    filters: {
      createYear: (value) => {
        if(!value){
          return value;
        }
        let time = timeMsec(value);
        return Moment(time).format('LL');
      }
    },
    computed:{
      removeImgTotal(){
        let removeImgTotal = 0;
        for(let v of this.removeIdList){
          removeImgTotal += v.imgNum;
        }
        return removeImgTotal;
      },
      removeVideoTotal(){
        let removeVideoTotal = 0;
        for(let v of this.removeIdList){
          removeVideoTotal += v.videoNum;
        }
        return removeVideoTotal;
      }
    },
    methods:{
      //点击删除文字
      clickRemoveText(){
        let ids = [];
        for(let v of this.removeIdList){
          ids.push({id:v.id});
        }
        if(ids.length==0){
          Toast('请选择要删除的藏品');
          return;
        }
        MessageBox.confirm('确定删除吗？删除后，无法恢复','').then(() => {
          deleteCollection({directoryId:this.albumId,ids:ids}).then(res => {
            if(res.data.reqResult.code > 0){
              this.isShowRemove = false;
              this.getAlbumPhotolist();
            }else {
              Toast(res.data.reqResult.msg);
            }
          })
        }).catch(()=>{})
      },
      //点击取消
      cancel(){
        this.isShowRemove = false;
      },
      //点击删除图标
      clickRemoveImg(){
        this.isShowRemove = true;
      },
      //点击图片进入图片详情
      goPhotoDetail(id){
        if(this.isShowRemove){
          return;
        }
        this.$router.push({name:'photoDetail',query:{photoId:id}});
      },
      //点击分享按钮
      clickShare(){
        MessageBox('', '请点击右上角“...”将相册分享给好友鉴赏吧');
      },
      //获取相册藏品列表
      getAlbumPhotolist(){
        let params = {
          directoryId:this.albumId,
          // pageNum:1,
          // pageSize:10,
        };
        getCollectionList(params).then(res => {
          if(res.data.reqResult.code > 0){
            this.albumPhotolist = res.data.data;
            let imgTotal = 0;
            let videoTotal = 0;
            for(let v of this.albumPhotolist){
              imgTotal += v.imgNum;
              videoTotal += v.videoNum;
            }
            this.imgTotal = imgTotal;
            this.videoTotal = videoTotal;
          }else {
            Toast(res.data.reqResult.msg);
          }
        })
      }
    }
  }
</script>

<style scoped>
  .album-detail-header{
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 0.75rem;
    padding-bottom: 0.45rem;
  }
  .album-title{
    color: #000000;
    font-size: 0.75rem;
    line-height: 0.75rem;
    font-weight: normal;
    width: 70%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .album-detail-header-right{
    display: flex;
    position: relative;
  }
  .album-detail-header-right:after{
    content: '';
    display: block;
    border-left: 1px solid #DCDCDC;
    height: 1.05rem;
    position: absolute;
    left: 1.4rem;
  }
  .album-detail-remove{
    width: 0.9rem;
    height: 1.05rem;
    background: url("../../../../../../static/images/collection/delete_1.png") no-repeat;
    background-size: contain;
    margin-right: 1.05rem;
  }
  .album-detail-share{
    width: 1.05rem;
    height: 1.05rem;
    background: url("../../../../../../static/images/collection/share_1.png") no-repeat;
    background-size: contain;
  }

  .photo-list-main{
    padding-bottom: 3rem;
  }
  .photo-list-box{
    /*padding: 0 0.75rem;*/
  }
  .photo-list-time{
    line-height:0.7rem;
    color: #666666;
    font-size: 0.7rem;
    margin-bottom: 0.9rem;
    padding: 0 4%;
  }
  .photo-list-img-box{
    display: flex;
    flex-wrap: wrap;
    padding: 0 4%;
  }
  .photo-list-img{
    width: 29.9vw;
    height: 29.9vw;
    margin-right: 1.15vw;
    margin-bottom: 1.15vw;
    position: relative;
    background-color: rgba(0,0,0,0.2);
  }
  .div-img{
    width: 100%;
    height: 100%;
    background-origin: content-box;
    background-position:50% 50%;
    background-size:contain;
    background-repeat:no-repeat;
    background-color: rgba(0,0,0,0.2);
  }
  .photo-list-img-box .photo-list-img:nth-child(3n+3){
    margin-right: 0;
  }
  .photo-list-img img{
    width: 100%;
  }
  .phpto-num{
    display: inline-block;
    background-color: rgba(0,0,0,0.65);
    color: #ffffff;
    font-size: 0.5rem;
    padding: 0.05rem 0.4rem;
    position: absolute;
    bottom: 0.5rem;
    left: 0.5rem;
    line-height: 0.5rem;
  }
  .phpto-video{
    position: absolute;
    left: 0.65rem;
    bottom: 0.5rem;
    color: #F4F4F4;
    font-size: 0.7rem;
    height: 0.7rem;
    line-height: 0.7rem;
    padding-left: 1.45rem;
    background-image: url("../../../../../../static/images/collection/video.png");
    background-repeat: no-repeat;
    background-size: 0.85rem;
    background-position: left center;
  }
  .album-detail-num{
    color: #333333;
    font-size: 0.7rem;
    margin-top: 0.4rem;
    text-align: center;
  }
  .album-add{
    display: block;
    width: 3rem;
    height: 3rem;
    background-image: url("../../../../../../static/images/collection/album_add.png");
    background-repeat: no-repeat;
    background-size: contain;
    position: fixed;
    right: 0.8rem;
    bottom: 3.25rem;
  }
  .photo-check-label{
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
  }
  .photo-check-label>div{
    width: 0.9rem;
    height: 0.9rem;
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
  }
  .weui-icon-checked:before {
    content: '\EA01';
    color: #ffffff;
    font-size: 0.9rem;
    display: block;
    margin: 0;
  }
  .weui-check:checked + .weui-icon-checked:before {
    content: '\EA06';
    color: #C50000;
  }
  .select-photo-header{
    display: flex;
    justify-content: space-between;
    height: 2.9rem;
    line-height: 2.9rem;
    border-bottom: 1px solid #EEEEEE;
    background-color: #ffffff;
    padding: 0 0.75rem;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
  }
  .select-header-left,.select-header-center{
    color: #000000;
    font-size: 0.7rem;
  }
  .select-header-right{
    color: #666666;
    font-size: 0.7rem;
  }
</style>
